package com.shaobufan.museum.controllar;

import com.shaobufan.museum.common.BaseResponse;
import com.shaobufan.museum.common.ResultUtils;
import com.shaobufan.museum.pojo.request.functions.FunctionsAlterRequest;
import com.shaobufan.museum.pojo.vo.FunctionsVo;
import com.shaobufan.museum.service.FunctionsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 验证码请求
 */
@RestController
@RequestMapping("/functions")
public class FunctionsController {
    @Resource
    FunctionsService functionsService;

    @ApiOperation("获取职能表")
    @GetMapping("/all")
    public BaseResponse<List<FunctionsVo>> getAllFunctions() {
        List<FunctionsVo> functionsVoList = functionsService.searchAllFunctions();
        return ResultUtils.success(functionsVoList, "全部职能表");
    }

    @ApiOperation("根据部门获取职能表")
    @GetMapping("/get/{params}")
    public BaseResponse<List<FunctionsVo>> getFunctionsByDepart(@PathVariable Integer params) {
        List<FunctionsVo> functionsVoList = functionsService.searchFunctionsByDepartId(params);
        return ResultUtils.success(functionsVoList, "职能表");
    }

    @ApiOperation("更改所属部门")
    @PostMapping("/alter")
    public BaseResponse<Boolean> alterFunctions(@RequestBody FunctionsAlterRequest functionsAlterRequest) {
        Boolean updated = functionsService.alterFunctions(functionsAlterRequest.getFunctionId(), functionsAlterRequest.getDepartId());
        return ResultUtils.success(updated,"更改所属部门");
    }
}